﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace PlayTrace
{
    public sealed class OnlyMsgConsoleListener : TraceListener
    {
        private string m_prefix;

        public OnlyMsgConsoleListener(string prefix)
        {
            m_prefix = prefix;
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            WriteLine(string.Format("EventType={0}, Message='{1}'", eventType, message));
        }

        public override void Write(string message)
        {
            Console.Write(ComposeMessage(message));
        }

        public override void WriteLine(string message)
        {
            Console.WriteLine(ComposeMessage(message));
        }

        private string ComposeMessage(string message)
        {
            return string.Format("[{0}]: {1}", m_prefix, message);
        }
    }

    public sealed class RecordListener : TraceListener
    {
        private readonly IList<string> m_messages;

        public RecordListener()
        {
            m_messages = new List<string>();
        }

        public IList<string> Messages { get { return m_messages; } }

        public override void Write(string message)
        {
            m_messages.Add("[Write    ]: " + message);
        }

        public override void WriteLine(string message)
        {
            m_messages.Add("[WriteLine]: " + message);
        }
    }
}
